package org.nstack.configuration;

import org.nstack.header.configuration.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.nstack.core.db.DatabaseFacade;


public class DefaultDiskOfferingFactory implements DiskOfferingFactory {
    public static DiskOfferingType type = new DiskOfferingType("DefaultDiskOfferingType");

    @Autowired
    private DatabaseFacade dbf;

    @Override
    public DiskOfferingType getDiskOfferingType() {
        return type;
    }

    @Override
    @Transactional
    public DiskOfferingInventory createDiskOffering(DiskOfferingVO vo, APICreateDiskOfferingMsg msg) {
        dbf.getEntityManager().persist(vo);
        dbf.getEntityManager().flush();
        dbf.getEntityManager().refresh(vo);
        return DiskOfferingInventory.valueOf(vo);
    }

    @Override
    public DiskOffering getDiskOffering(DiskOfferingVO vo) {
        return new DiskOfferingBase(vo);
    }
}
